/**
 * 
 */
package br.com.plurianual.model.dao.impl;

import javax.persistence.Query;

import br.com.plurianual.exception.DataAccessLayerException;
import br.com.plurianual.model.dao.ProgramaDAO;
import br.com.plurianual.model.entity.Programa;

/**
 * @author FRAGA
 *
 */
public class ProgramaDAOImpl extends DAOImpl<Programa, Integer> implements
		ProgramaDAO {

	@Override
	public final void deleteAndClearOrphans(Programa programa) throws DataAccessLayerException {
		try {
			log.debug("Delete object: " + getPersistentClass().getName());
			
			Query clearIndicadorQuery = this.getEntityManager().createNamedQuery("deletePrograma.clearIndicador");
			Query clearAcaoQuery = this.getEntityManager().createNamedQuery("deletePrograma.clearAcao");

			clearIndicadorQuery.setParameter("programa", programa);
			clearAcaoQuery.setParameter("programa", programa);
			
			clearIndicadorQuery.executeUpdate();
			clearAcaoQuery.executeUpdate();
			
			this.delete(programa);
		} catch (Exception e) {
			handleException(e);
		}
	}
}
